﻿$(document).ready(function () {
    //init menu blob
    $('#nav').spasticNav();
});

jQuery.fn.inputHints = function () {
    // show the display text
    $(this).each(function (i) {
        $(this).val($(this).attr('title'))
            .addClass('hint');
    });

    // hook up the blur & focus
    return $(this).focus(function () {
        if ($(this).val() == $(this).attr('title'))
            $(this).val('')
                .removeClass('hint');
    }).blur(function () {
        if ($(this).val() == '')
            $(this).val($(this).attr('title'))
                .addClass('hint');
    });
};

function eventSignup(id, authToken) {
    debugger;
    $.ajax({
        url: "/../Events/Attend",
        global: false,
        type: "POST",
        data: { eventId: id, main: true },
        dataType: "json",
        async: true,
        success: function (data) {
            $("#signUp").hide();
            addAttendingMessage();
            $("#attending").show();
            signupSuccess();
            $(".attendees").html('');
            $.each(data.Attendees, function (i, attendee) {
                rebuildAttendeeList(i, attendee.Name);
            });
        }
    });
}

function rebuildAttendeeList(index, name) {
    $(".attendees").append('<div>');

    if (index % 2 == 0) {
        $(".attendees").append('<div style="float:left; width:315px; padding:5px;">' + name + '</div>');
    }
    else {
        $(".attendees").append('<div style="float:right; width:300px;padding:5px;"> <div style="float:left;">' + name + '</div></div>');
    }
    $(".attendees").append('</div>');
}

function addAttendingMessage() {
    $("#eventSignupMain").prepend('<div id="attending" style="height:25px;line-height:23px;"><img style="vertical-align:middle;" src="../../../Images/information.png" alt="" /><span><strong>You are attending this event!</strong></span></div>');
}

function signupSuccess() {
    $("#attending").animate({ backgroundColor: "#49E20E" }, 100);
    $("#attending").animate({ backgroundColor: "white" }, 6000);
}

function commentPosted() {
        $("#successMessage").slideDown('slow');
        setTimeout(function () { $("#successMessage").slideUp('slow'); }, 5000);
}

